<?php

namespace App\Http\Controllers;

use App\Content;
use App\Novel;
use App\Vol;
use Illuminate\Http\Request;

class VolController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        return view('admin.novel.vol',['vols'=>Vol::where('vol_nid',$request->id)->paginate(10)]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        return view('admin.vol.add',['id'=>$request->id]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $vol=new Vol;
        $vol->vol_nid=$request->id;
        $vol->volname=$request->volname;
        $vol->save();
        return back();
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Vol  $vol
     * @return \Illuminate\Http\Response
     */
    public function show(Request $request)
    {
        $vols=[];
        $volList=Vol::where('vol_nid',$request->id)->orderBy('id',' esc')->get();
        foreach ($volList as $vol){
            $vols[$vol->volname]=Content::where('con_nid',$request->id)->where('con_vid',$vol->id)->orderBy('id','esc')->get();
        }

        return view('index.vol',['vols'=>$vols,
            'novel'=>Novel::find($request->id)

        ]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Vol  $vol
     * @return \Illuminate\Http\Response
     */
    public function edit(Vol $vol)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Vol  $vol
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request)
    {
        $vol=Vol::findOrFail($request->id);
        $vol->update($request->all());
        return back();
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Vol  $vol
     * @return \Illuminate\Http\Response
     */
    public function destroy(Request $request)
    {
        
        Vol::destroy($request->id);
        return back();
    }
}
